package com.example.androidlearing2423.kotlin

//循环结构
fun main (){
    val scores = intArrayOf(88,100,78,99,76,65,74,95)
    var sum = 0
    for (score in scores){
        sum += score
    }
    val average = scores.sum() / scores.size
    println(average)
  }
 private fun sum3 (){
    //求1-100的奇数和，包括1和100
    var sum = 0
    for (i in 1 .. 100  step 2){
        sum += i
    }
    println(sum)
}
private fun sum2(){
    //求1-100的和，包括1但不包括100
    var sum = 0
    for (i in 1 .. 100  ){
        sum += i
    }
    println(sum)
}
private fun sum4 (){
    //求1-100的奇数和，包括1和100
    var sum = 0
    for (i in 1 downTo  100  step 2){
        sum += i
    }
    println(sum)
}